<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<lv-form class="aui-gutter-column-lg">
    <lv-form-item>
        <lv-form-label>{{'protection_selected_copy_label' | i18n}}</lv-form-label>
        <lv-form-control>
            {{rowCopy?.display_timestamp | date: 'yyyy-MM-dd HH:mm:ss'}}
        </lv-form-control>
    </lv-form-item>
</lv-form>
<h3 class="aui-gutter-column-md">{{'protection_recovery_selected_disk_label' | i18n}}</h3>
<div class="recovery-table">
    <lv-pro-table [data]="restoreTableData" [config]="restoreTableConfig"></lv-pro-table>
</div>
<div class="recovery-conifg">
    <h3 class="aui-gutter-column-md">{{'protection_restore_file_config_label' | i18n}}</h3>
    <lv-form [formGroup]="formGroup" class="formGroup" lvKeepRequiredWidth>
        <lv-form-item>
            <lv-form-label>
                {{ 'protection_restore_to_label' | i18n }}
            </lv-form-label>
            <lv-form-control>
                <lv-radio-group formControlName="restoreTo" [lvGroupName]="'restoreToGroup'">
                    <lv-group [lvGutter]="'20px'">
                        <lv-radio [lvValue]="restoreLocationType.ORIGIN" [lvDisabled]="restoreToNewLocationOnly"
                            [lv-tooltip]="restoreToNewLocationOnly ? ('protection_cloud_origin_restore_disabled_label' | i18n) : ''">
                            {{ 'common_restore_to_origin_location_label' | i18n }}
                        </lv-radio>
                        <lv-radio [lvValue]="restoreLocationType.NEW">
                            {{ 'common_restore_to_new_location_label' | i18n }}
                        </lv-radio>
                    </lv-group>
                </lv-radio-group>
            </lv-form-control>
        </lv-form-item>
        <lv-form-item>
            <lv-form-label lvRequired>{{'protection_volume_restore_target_label' | i18n}}</lv-form-label>
            <lv-form-control>
                <ng-container *ngIf="formGroup.value.restoreTo === restoreLocationType.ORIGIN; else elseTemplate">
                    {{resourceProperties?.path}}
                </ng-container>
                <ng-template #elseTemplate>
                    <lv-tree-select [lvTreeData]="serverTreeData" lvTreeSelectionMode="single"
                        formControlName="targetServer" lvShowClear lvTreeShowLine
                        (lvExpandedChange)="expandedChange($event)">
                        <lv-treeselect-trigger>
                            <span>{{ formGroup.value.targetServer[0]?.path | nil }}</span>
                        </lv-treeselect-trigger>
                    </lv-tree-select>
                </ng-template>
            </lv-form-control>
        </lv-form-item>
        <lv-group lvGutter='4px' class="disk-type-warn" *ngIf="showTypeWarn()">
            <i lv-icon="lv-icon-status-warning-info"></i>
            <span class="aui-text-label">
                {{ 'protection_openstack_disk_type_diff_label' | i18n }}
            </span>
        </lv-group>
        <div class="aui-gutter-column-xl target-table">
            <lv-pro-table [data]="targetTableData" [config]="targetTableConfig"></lv-pro-table>
        </div>
        <lv-collapse [lvMultiExpansion]="'false'" lvType="simple">
            <lv-collapse-panel [lvTitle]="titleTpl" [lvExpanded]="false">
                <lv-form-item>
                    <lv-form-label>
                        {{'protection_proxy_host_label' | i18n}}
                    </lv-form-label>
                    <lv-form-control>
                        <lv-select [lvOptions]="proxyOptions" formControlName="proxyHost" lvValueKey='value'
                            lvShowCheckAll lvShowFilter lvFilterKey="label" lvFilterMode="contains" lvMode="multiple"
                            lvPlaceholder="{{'protection_agent_placeholder_label' | i18n}}">
                        </lv-select>
                    </lv-form-control>
                </lv-form-item>
                <lv-form-item>
                    <lv-form-label>{{'protection_auto_power_on_label' | i18n}}</lv-form-label>
                    <lv-form-control>
                        <lv-switch formControlName="restoreAutoPowerOn"></lv-switch>
                    </lv-form-control>
                </lv-form-item>
                <lv-form-item>
                    <lv-form-label>{{'common_restore_before_copy_verify_label' | i18n}}
                        <i lv-icon="aui-icon-help"
                            lv-tooltip="{{'protect_hcs_restore_before_copy_verify_label' | i18n}}"
                            lvTooltipPosition="rightTop" lvTooltipTheme="light" class="configform-constraint"
                            lvColorState='true'></i>
                    </lv-form-label>
                    <lv-form-control>
                        <lv-switch formControlName="copyVerify"
                            [lv-tooltip]="verifyStatus === CopyDataVerifyStatus.noGenerate.value ? copyVerifyDisableLabel : ''"
                            [lvDisabled]="verifyStatus === CopyDataVerifyStatus.noGenerate.value">
                        </lv-switch>
                    </lv-form-control>
                </lv-form-item>
            </lv-collapse-panel>
        </lv-collapse>
    </lv-form>
</div>

<ng-template #sizeTpl let-item>
    {{item.sizeDisplay}}&nbsp;
</ng-template>

<ng-template #recoveryTypeTpl let-item>
    <lv-select class="type-select" [lvOptions]="typeOptions" lvPanelClass="openstack-restore-panel"
        [(ngModel)]="item.recoveryType" (ngModelChange)='diskChange($event, item)' lvValueKey='value'>
    </lv-select>
</ng-template>

<ng-template #diskDeviceTpl let-item>
    <ng-container *ngIf="item.recoveryType === NEW_DISK; else elseTemplate">
        <lv-group lvGutter='4px'>
            <input lv-input type="text" [(ngModel)]="item.targetDiskName" class="disk-name-input"
                placeholder="{{'protection_recovery_new_disk_placeholder_label' | i18n}}"
                (ngModelChange)="diskNameChange()" />
            <lv-select class="disk-domain-select" [lvOptions]="volumeTypeOptions" [(ngModel)]="item.targetVolumeType"
                lvValueKey='value' (ngModelChange)="diskDomainChange()"
                lvPlaceholder="{{'protection_recovery_new_disk_type_placeholder_label' | i18n}}">
            </lv-select>
        </lv-group>
    </ng-container>
    <ng-template #elseTemplate>
        <lv-select class="disk-select"
            [lvDisabled]='!formGroup.value.targetServer?.length && formGroup.value.restoreTo === restoreLocationType.NEW'
            [lvOptions]="item.targetDiskOptions" lvPanelClass="openstack-restore-panel" [(ngModel)]="item.targetDisk"
            lvShowFilter lvFilterKey="label" lvFilterMode="contains" (ngModelChange)='diskChange($event, item)'
            lvValueKey='id' lvShowClear>
        </lv-select>
    </ng-template>
</ng-template>

<ng-template #titleTpl>
    <lv-group lvGutter='8px'>
        <span class="custom-collapse-title-text">{{'common_advanced_label'|i18n}}</span>
    </lv-group>
</ng-template>